<%-- 
    Document   : editManager
    Created on : Dec 19, 2014, 4:49:18 PM
    Author     : DucND
--%>
<%@page import="dao.ManagerDAO"%>
<%@page import="entity.Manager"%>
<jsp:include page="../header.jsp"></jsp:include>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    String username = (String) request.getSession().getAttribute("Username");
    if (!ManagerDAO.isAdmin(username)) {
        response.sendRedirect("../public/index.jsp");
    }
    username = request.getParameter("username");
    String email = "";
    String role = "";
    Manager ma = ManagerDAO.getManagerInfo(username);
    String saveBtn = request.getParameter("saveBtn");
    if (saveBtn == null) {
        email = ma.getEmail().trim();
        role = ma.getRole() == true ? "Admin" : "Manager";
    } else {
        email = request.getParameter("email");
        role = request.getParameter("role");
        ma.setUsername(username);
        ma.setEmail(email);
        ma.setRole(role.equals("Admin") ? true : false);
        ManagerDAO.edit(ma);
        response.sendRedirect("listManager.jsp");
    }
%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Untitled Document</title>
    </head>

    <body>
        <div class="container">
            <h2>Edit Manager</h2>
            <hr>
            <form action="editManager.jsp?username=<%=username%>" method="POST">
                <table width="50%" style="border-collapse: separate; border-spacing: 20px">
                    <tr>
                        <td width="30%">&nbsp;</td>
                        <td width="70%">&nbsp;</td>
                    </tr>

                    <tr>
                        <td>Username </td>
                        <td><input name="username" type="text" class="form-control" value="<%=username%>" disabled=""/>
                        </td>
                    </tr>
                    <tr>
                        <td>Email(<font color="red">*</font>) </td>
                        <td><input name="email" type="text" class="form-control" value="<%=email%>" required/></td>
                    </tr>
                    <tr>
                        <td>Role(<font color="red">*</font>) </td>
                        <td>
                            <input type="radio" name="role" value="Manager" <%if (role.equals("Manager")) {%> checked <%}%> /> Manager
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" name="role" value="Admin" <%if (role.equals("Admin")) {%> checked <%}%> /> Admin
                        </td>                      
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td><input name="saveBtn" type="submit" value="Save" class="btn btn-success" style="width: 100px"/></td>
                        <td><a href="listManager.jsp"><input type="button" value="Cancel" class="btn btn-danger" style="width: 100px"/></a></td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
</html>
<jsp:include page="../footer.jsp"></jsp:include>